package org.lejos.example;

// TouchsensorEx2.java
// Two sensors
// When wall is hit, turn to left or right

import gin.and.tonic.*;

public class TouchsensorEx2
{
  private NxtRobot robot = new NxtRobot();
  private Gear gear = new Gear();

  public TouchsensorEx2()
  {
    TouchSensor ts1 = new TouchSensor(SensorPort.S1);
    TouchSensor ts2 = new TouchSensor(SensorPort.S2);
    robot.addPart(ts1);
    robot.addPart(ts2);
    ts1.addTouchListener(new TouchAdapter()
    {
      public void pressed()
      {
        gear.backward(500);
        gear.left(100);
        gear.forward();
      }
    });

    ts2.addTouchListener(new TouchAdapter()
    {
      public void pressed()
      {
        gear.backward(500);
        gear.right(100);
        gear.forward();
      }
    });

    gear.setSpeed(30);
    robot.addPart(gear);
    gear.forward();

    Tools.waitEnter("ENTER to quit");
    robot.exit();
  }

  public static void main(String[] args)
  {
    new TouchsensorEx2();
  }
}